package com.LeeCode;

/**
 * 数组的最小相等和
 */

public class Code2918 {
    public static void main(String[] args) {
        int[] nums1 = {1,2,3,2};
        int[] nums2 = {1,4,3};
        System.out.println(new Code2918().minSum(nums1, nums2));
    }

    public long minSum(int[] nums1, int[] nums2) {
        long sum1 = 0, sum2 = 0, count1 = 0, count2 = 0;
        for (int num : nums1) {
            sum1 += num;
            if (num == 0)
                count1++;
        }

        for (int num : nums2) {
            sum2 += num;
            if (num == 0)
                count2++;
        }

        if ((sum1 + count1) <= (sum2 + count2) && count1 != 0) {
            return sum2 + count2;
        } else if ((sum1 + count1) >= (sum2 + count2) && count2 != 0) {
            return sum1 + count1;
        }else if(sum1 == sum2 && count1 == 0 && count2 == 0){
            return sum1;
        }
        return -1;
    }
}
